import React, { useEffect, useState } from "react";
import {
  Form,
  Input,
  Button,
  Dialog,
  Checkbox,
  Space,
  DatePicker,
  Toast,
} from "antd-mobile";
import { FormInstance } from "antd-mobile/es/components/form";
import dayjs from "dayjs";
import { CloseCircleFill } from "antd-mobile-icons";
import { useNavigate } from "react-router-dom";
import axios from "axios";
const Index: React.FC = () => {
  const navigate = useNavigate();
  const [form] = Form.useForm();
  const [tel, setTel] = useState("");
  
  const onSubmit = () => {
    const values = form.getFieldsValue();
    //  console.log( form.getFieldsValue())
     let zh=values.c
     let mm=values.d
     axios.post("/api/login", { tel: zh }).then((resp) => {
      let { code, msg, token, useritem } = resp.data;
      if (code == 200) {
        Toast.show({
          content: `登录成功`,
        });
        localStorage.setItem("token", token);
        localStorage.setItem("useritem", JSON.stringify(useritem));
        navigate("/home/home");
      }
    });
  };
  

  return (
    <div className="login">
 
      <div className="login-bottom">
        <Form
          form={form}
          initialValues={{
            c:"",
            d:""
          }}
          footer={
            <Button block color="primary" onClick={onSubmit} size="large">
              登录
            </Button>
          }
        >
          <Form.Item name="c" label="手机号" required>
            <Input placeholder="请输入手机号" />
          </Form.Item>
          <Form.Item name="d" label="密码" required>
            <Input placeholder="请输入密码" />
          </Form.Item>
        </Form>
        <div><a onClick={()=>navigate('/sigin')}>还没有注册？</a></div>
      </div>
    </div>
  );
};

export default Index;
